
/******************************************************************************\
|    Title:        	 Table E2: Regression Models for Switching Across Threshold|
|    Date:         	 July 2023	                                         	   |
|    Author:         Elisa Wirsching	      							       |
\******************************************************************************/


clear all
set more off, permanently
numlabel, add
set maxvar 32000


use congress_yearly.dta, clear

*------------------------------------------------------------------------------*
*							Switching behavior by quantiles					   *	
*------------------------------------------------------------------------------*

* Note that I care about the LANDING quantile of staffers, i.e. I want
* changes between year t and t+1 (instead of t-1 and t as in the main analysis).

* We therefore need to redefine the treatment period (after HLOGA) and the switching indicator.
* Administrative staff is excluded since they have a cutoff different from the 75% (see manuscript for details).

gen posttreat2 = 0
replace posttreat2 = 1 if year>=2007

xtset stafferid year
gen switchtouncovered2 = F.switchtouncovered_treatment if nonadmin_everyear==1
gen switchtocovered2 = F.switchtocovered_treatment if nonadmin_everyear==1

*****************************************
* Quantiles for switchers into coverage
capture drop groups tocovered
xtile groups = percent_annualpay if percent_annualpay<=0.75 & switchtocovered2!=., n(100)


*****************************************
* Quantiles for switchers out of coverage

capture drop groups2 touncovered
xtile groups2 = percent_annualpay if percent_annualpay>0.75 & switchtouncovered2!=., n(11)



**************************************
** Switches to covered (right below)

xtset stafferid year

reg switchtocovered2 posttreat2 if percent_annualpay<=0.75 & percent_annualpay>=0.65, robust
summarize switchtocovered2 if e(sample)==1
estadd scalar ymean = r(mean) 
est store mod1

reg switchtocovered2 posttreat2 daysworked committeestaff_everyear personalstaff_everyear senate_everyear dcoffice_everyear leaderofficestaff_everyear if percent_annualpay<=0.75 & percent_annualpay>=0.65, robust
summarize switchtocovered2 if e(sample)==1
estadd scalar ymean = r(mean) 
est store mod2
estadd local fixed "Yes" , replace



**************************************
** Switches to uncovered (right above)

reg switchtouncovered2 posttreat2 if percent_annualpay>0.75 & percent_annualpay<=0.90, robust
summarize switchtouncovered2 if e(sample)==1
estadd scalar ymean = r(mean) 
est store mod3

reg switchtouncovered2 posttreat2 daysworked committeestaff_everyear personalstaff_everyear senate_everyear dcoffice_everyear leaderofficestaff_everyear if percent_annualpay>0.75 & percent_annualpay<=0.90, robust
summarize switchtouncovered2 if e(sample)==1
estadd scalar ymean = r(mean) 
est store mod4
estadd local fixed "Yes" , replace

esttab mod1 mod2 mod3 mod4 using "TABLED2.csv", replace ///
	b(3) se(3) star(* .05 ** .01 *** 0.001) keep(posttreat2) coeflabels(posttreat2 "After HLOGA") ///
	stats(fixed ymean N r2, fmt(0 3 0 3) labels("Controls" "Mean of DV" "Observations" "R2")) ///
	label parentheses nogaps nolines noeqlines ///
    noomitted nodepvars nobaselevels nonotes noconstant ///
	nomtitles mgroups("Switch to covered" "Switch to uncovered", pattern(1 0 1 0))
